home *** CD-ROM | disk | FTP | other *** search
- /*------------------------------------------------------------------------------
- File: ScriptRunnerAgent.cpp
-
- Contains: The ScriptRunnerAgent SOM class implementation.
-
- Written by: Sue Dumont
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- ------------------------------------------------------------------------------*/
-
- // -- Compiler/Preprocessor Switches --
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (eg. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with the "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- ScriptRunnerAgent Includes --
-
- // Notification that this is a SOM source file
- #define Sample_ScriptRunnerAgent_Class_Source
-
- // define underscore field names (ie. _fSelf)
- #define VARIABLE_MACROS
-
- #ifndef SOM_Sample_ScriptRunnerAgent_xih
- #include "ScriptRunnerAgent.xih"
- #endif
-
- // -- ScriptRunner includes --
-
- #ifndef SOM_SampleCode_ScriptRunner_xh
- #include "ScriptRunner.xh"
- #endif
-
- #ifndef SOM_Samples_PaletteExt_xh
- #include "PaletteExt.xh"
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _ODMEMORY_
- #include <ODMemory.h>
- #endif
-
- #ifndef _ISOSTR_
- #include <ISOStr.h>
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- // -- Mac Includes --
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #pragma segment ScriptRunnerAgent
-
- //==============================================================================
- // ScriptRunnerAgent
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Method: somInit
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK ScriptRunnerAgent__somInit(Sample_ScriptRunnerAgent *somSelf)
- {
- Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
- Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent","somInit");
-
- // somInit and somUninit methods behave like C++ constructors in that the
- // inherited methods are called automatically.
- // Thus, there is no need to call the parent class' somInit or somUninit.
-
- // There is also no need to set instance variables to zero/NULL
- // since SOM guarantees that a newly constructed object is zeroed.
- }
-
- //------------------------------------------------------------------------------
- // Method: somUninit
- //------------------------------------------------------------------------------
- SOM_Scope void
- SOMLINK ScriptRunnerAgent__somUninit(Sample_ScriptRunnerAgent *somSelf)
- {
- Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
- Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent", "somUninit");
- }
-
- //------------------------------------------------------------------------------
- // Method: AcquireScriptRunner
- // Origin: ScriptRunnerAgent
- //
- // Description: This method calls the draft to create the ScriptRunner
- // part, and returns the palette extension as a result.
- // The client part is responsible for releasing this
- // extension.
- //------------------------------------------------------------------------------
- SOM_Scope ODExtension*
- SOMLINK ScriptRunnerAgent__AcquireScriptRunner
- (
- Sample_ScriptRunnerAgent* somSelf,
- Environment* ev,
- ODDraft* draft
- )
- {
- Sample_ScriptRunnerAgentData *somThis = Sample_ScriptRunnerAgentGetData(somSelf);
- Sample_ScriptRunnerAgentMethodDebug("ScriptRunnerAgent", "AcquireScriptRunner");
-
- ODExtension* extension = kODNULL;
-
- SOM_TRY
- // Get the draft's current permissions.
- ODBoolean writeAccess = ( draft->GetPermissions(ev) >= kODDPSharedWrite );
-
- if ( writeAccess )
- {
- // If the ScriptRunner part exists, acquire it through the
- // window ID. If not, call the draft's CreatePart method.
-
- if ( _fScriptRunnerID )
- {
- // If the ScriptRunner ID is not null, make sure it's valid.
- TempODWindow window = ODGetSession(ev, draft)->GetWindowState(ev)
- ->AcquireWindow(ev, _fScriptRunnerID);
- if ( window )
- {
- TempODPart part = window->GetRootFrame(ev)->AcquirePart(ev);
- extension = part->AcquireExtension(ev, kPaletteExtension);
- }
- else
- {
- // Window not found. Set the ID back to null so the
- // ScriptRunner part can be created.
- _fScriptRunnerID = kODNULLID;
- }
- }
-
- if ( _fScriptRunnerID == kODNULLID )
- {
- // CreatePart will create the part and construct the real part by
- // calling its InitPart method. You can only call CreatePart if
- // the draft's permissions allow write access.
- TempODPart part = draft->CreatePart(ev, kScriptRunner, kODNoEditor);
- _fScriptRunnerID = part->Open(ev, kODNULL);
- extension = part->AcquireExtension(ev, kPaletteExtension);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return extension;
- }
-